package com.maniu.fluttermaniu;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

import androidx.annotation.NonNull;

//native 层渲染   到  FlutterSurfaceView
public class FlutterSurfaceView  extends SurfaceView implements SurfaceHolder.Callback {
    private FlutterJNI flutterJNI = new FlutterJNI();
    public FlutterSurfaceView(Context context) {
        super(context);
    }

    public FlutterSurfaceView(Context context, AttributeSet attrs) {
        super(context, attrs);
        getHolder().addCallback(this);
    }

    public FlutterSurfaceView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public void surfaceCreated(@NonNull SurfaceHolder surfaceHolder) {
//        利用Skia引擎 帮助我们渲染    surface   做到这一点        理论 实践起来 没问题
//         JNI函数   --> native
       Surface surface= getHolder().getSurface();
        flutterJNI.init(surface, getWidth(), getHeight());
        flutterJNI.drawText("david-----love----99", 350, 150);
        flutterJNI.flush();

    }

    @Override
    public void surfaceChanged(@NonNull SurfaceHolder surfaceHolder, int i, int i1, int i2) {

    }

    @Override
    public void surfaceDestroyed(@NonNull SurfaceHolder surfaceHolder) {

    }
}
